'''
@see c22_dp/2D/problem_longest_common_subsequence.py
'''

def longestCommonSubsequence(s1: str, s2: str):
    m, n = len(s1), len(s2)
    dp = [[0] * n for _ in range(m)]
    dp[0][0] = 1 if s1[0] == s2[0] else 0
    for i in range(1, m):
        dp[i][0] = 1 if s1[i] == s2[0] else dp[i - 1][0]
    for j in range(1, n):
        dp[0][j] = 1 if s1[0] == s2[j] else dp[0][j - 1]
    for i in range(1, m):
        for j in range(1, n):
            p1 = 1 + dp[i - 1][j - 1] if (s1[i] == s2[j]) else 0
            p2 = dp[i][j - 1]
            p3 = dp[i - 1][j]
            dp[i][j] = max(p1, p2, p3)
    res = []
    i, j = m -1 , n -1
    while i >= 0 and j >= 0:
        if s1[i] == s2[j]:
            res.append(s1[i])
            i, j = i - 1, j - 1
        else:
            if i - 1 >= 0 and dp[i-1][j] == dp[i][j]:
                i -= 1
            else:
                j-=1
    return ''.join(res[::-1]) if res else -1

s1 = input()
s2 = input()
res = longestCommonSubsequence(s1, s2)
print(res)
